###############################################################################
# SuperLinks                                                                  #
# Copyright (c) 2000-2007 Greg Nolle (http://greg.nolle.co.uk)                #
###############################################################################
# This program is free software; you can redistribute it and/or modify it     #
# under the terms of the GNU General Public License as published by the Free  #
# Software Foundation; either version 2 of the License, or (at your option)   #
# any later version.                                                          #
#                                                                             #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       #
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   #
# more details.                                                               ##                                                                             #
# You should have received a copy of the GNU General Public License along     #
# with this program; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                 #
###############################################################################
# ControlPanel/Output/Reviews.pm.pl -> Reviews module                         #
###############################################################################
# DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!                         #
###############################################################################
package Skin::CP::Reviews;

BEGIN { require "System.pm.pl"; import System qw($SYSTEM); }
BEGIN { require "General.pm.pl"; import General qw($GENERAL); }
require "Standard.pm.pl";
require "Tables.pm.pl";

use strict;

sub new {
  my ($class) = @_;
  my $self    = {};
  return bless ($self, $class);
}

sub DESTROY { }

###############################################################################
# show subroutine
sub show {
  my $self = shift;
  my %in = ("input" => {}, @_);

  #----------------------------------------------------------------------#
  # Printing page...                                                     #

  my @Fields = (
    {
      title     => "Del",
      width     => "1",
      template  => sub { my ($s, $d, $f, $r) = @_;
        return { body => $f->CheckBox(name => "RevID", items => [{ value => $r->{'ID'} }]) };
      }
    },
    {
      title     => "ID",
      width     => "45",
      sort      => "ID",
      nowrap    => 1,
      template  => sub { my ($s, $d, $f, $r) = @_;
        return { body => $r->{'ID'} };
      }
    },
    {
      title     => "Review",
      width     => "65%",
      sort      => "REVIEW",
      main      => 1,
      template  => sub { my ($s, $d, $f, $r) = @_;
        return { body => $r->{'REVIEW'} };
      }
    },
    {
      title     => "Name",
      width     => "100",
      nowrap    => 1,
      sort      => "NAME",
      template  => sub { my ($s, $d, $f, $r) = @_;
        return { body => $r->{'NAME'} };
      }
    },
    {
      title     => "IP",
      width     => "100",
      nowrap    => 1,
      sort      => "IP",
      template  => sub { my ($s, $d, $f, $r) = @_;
        return { body => $r->{'IP'} };
      }
    },
    {
      title     => "Created",
      width     => "100",
      nowrap    => 1,
      sort      => "CREATE_TIME",
      template  => sub { my ($s, $d, $f, $r) = @_;
        return { body => "$r->{'CREATE_DATE'} at $r->{'CREATE_TIME'}" };
      }
    },
    {
      title     => "",
      width     => "35%",
      template  => sub { my ($s, $d, $f, $r) = @_;
        return { body => $d->TableToolbar(
          items => [
            { type => "divider" },
            { type => "icon", url => "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=ModifyReview&RID=$r->{'resource'}->{'ID'}&RevID=$r->{'ID'}&Referer=".$SL::CGI->escape($s->URL())."&SID=$SL::ADMIN{'SID'}", icon => "Toolbar/modify.gif", caption => "Modify" },
            { type => "icon", url => "javascript:ConfirmRemove('$SYSTEM->{'SCRIPT_URL'}?CP=1&action=DoRemoveReviews&RID=$r->{'resource'}->{'ID'}&RevID=$r->{'ID'}&Referer=".$SL::CGI->escape($s->URL())."&SID=$SL::ADMIN{'SID'}');", icon => "Toolbar/remove.gif", caption => "Remove" }
          ]
        ) };
      }
    }
  );    

  foreach my $review (@{ $in{'input'}->{'REVIEWS'} }) {
    $review->{'resource'} = $in{'input'}->{'RESOURCE'};
  }

  my $Tables = Tables->new();

  return $Tables->Build(
    header      => "Reviews",
    records     => $in{'input'}->{'REVIEWS'},
    pages       => $in{'input'}->{'PAGES'},
    fields      => \@Fields,
    form_extra  => { onSubmit => "return ConfirmRemove();" },
    del_field   => "RevID",
    hiddens     => [
      { name => "RID", value => $in{'input'}->{'RESOURCE'}->{'ID'} },
      { name => "action", value => "DoRemoveReviews" },
      { name => "CP", value => "1" },
      { name => "SID", value => $SL::ADMIN{'SID'} }
    ]
  );
}

1;